package com.information.service.iml;

import com.information.service.AdministratorService;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class AdministratorServiceIml implements AdministratorService {

	@Override
	public Ret verifyLanding(String name, String password) {
		Ret ret = new Ret();
		// 判断用户名是否为空 isBlank==>空为true
		if (StrKit.isBlank(name)) {
			ret.setFail();
			ret.set("message", "参数异常");
			return ret;
		}
		String sql = "select * from administrator where 1=1 and name = ? ";
		Record admin = Db.findFirst(sql, name);
		if (null == admin) {
			ret.setFail();
			ret.set("message", "用户名为空");
			return ret;
		}
		// 获取admin对象中的password字段的值
		String sqlpwd = admin.getStr("password");
		// notBlank==>不为空为true
		if (StrKit.notBlank(password) && StrKit.notBlank(sqlpwd)) {
			if (password.equals(sqlpwd)) {
				ret.setOk();
				ret.set("message", "您好管理员");
				return ret;
			} else {
				ret.setFail();
				ret.set("message", "密码错误");
				return ret;
			}
		}
		ret.setFail();
		ret.set("message", "参数异常");
		return ret;
	}

}
